package cn.bugstack.types.design.framework.tree;


import lombok.Getter;
import lombok.Setter;

/**
 * @author 丨一
 * @version 1.0
 * @title AbstractStrategyRouter
 * @description:
 * @date 2025/7/25 下午4:50
 */
public abstract class AbstractStrategyRouter<T, D, R> implements StrategyHandler<T, D, R>, StrategyMapper<T, D, R> {

    //默认实例
    @Getter
    @Setter
    protected StrategyHandler<T, D, R> defaultStrategyHandler = StrategyHandler.DEFAULT;


    //策略路由
    public R router(T requestParameter, D dynamicContext) throws Exception {
        StrategyHandler<T, D, R> strategyHandler = this.get(requestParameter, dynamicContext);

        //获取策略
        if (strategyHandler != null) return strategyHandler.apply(requestParameter, dynamicContext);
        else return defaultStrategyHandler.apply(requestParameter, dynamicContext);
    }

}
